<script src="{{ getAssets }}lodop/LodopFuncs.js?v=v1.0.3"></script>
<script language="javascript">
$(function(){
	$.post('{{urlfor "ArchivesController.GetInterrogations"}}/{{.m.Id}}', {}, function(json){
		
		if(json.status == 1) {
			layer.msg(json.msg);
			return false;	
		}
		
		receiveFormData(json.data);
		
	}, 'json');	
	
});
var checkbox = ['BeforeConclusion', 'BeforeTreatment', 'PastHistory', 'Environment', 'RefractionOd', 'RefractionOs', 'AmblyopiaOd','AmblyopiaOs','Proposal', 'Inheritance'];
function receiveFormData(d) {
	if(!d) return false;
	
	for (var key in d){
		 val = d[key]
		 if(in_array(key, checkbox)) {
			checkboxDefault(key, val, '[]');
		 }else if(key == 'Archives') {
			 $("[name='Archives']").val(val.Id);
		 }else if(key == 'Number') {
			 $("[id='Number']").html(val);
		 }else if(key == 'UpdatedAt') {
			 $("[id='created_at']").html('，'+timetrans(val));
		 }else{
			$("[name='"+ key +"']").val(val);
		 }
	}
}
function in_array(search,array){
    for(var i in array){
        if(array[i]==search){
            return true;
        }
    }
    return false;
}
function checkboxDefault(key, value, affix) {
	value = ','+value+',';
	$('input[name="'+ key + affix +'"]').each(function(index, element) {
        if(value.indexOf(','+ $(this).val()+',') != -1) {
			$(this).prop('checked', true);
		}
    });
}
function print_table() {
    var style = "<style>\
        .h1{ text-align: center; font-size: 25px; display: block; padding-bottom: 20px;}\
        .p{ text-align: center; font-size: 15px; display: block; }\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse;}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:left; color:#333; line-height: 22px; font-size: 12px; white-space:nowrap;}\
		.tables tbody td textarea{ width: 100%;}\
		.tables tbody td input[type=\"text\"]{ width: 100%;}\
		</style>";
    LODOP=getLodop();
    LODOP.SET_PRINT_PAGESIZE(0,'297mm', '210mm',"A4");
    LODOP.ADD_PRINT_HTM(20,25,0,'100%', style + '<body><div class="h1">'+ WG.fullname  +' 问诊记录</div>' + $('#print_table').html() + '<p class="p">地址：'+ WG.address +'，联系电话：'+ WG.shopownerTel  +'</p></body>');
    LODOP.PREVIEW();
}
$('#action_btn').append('<a href="javascript:;" onclick="print_table();return false;" class="am-btn am-btn-secondary am-round am-btn-xs">打印问诊</a>');
</script>